package cn.appsys.web.instener;

import org.springframework.web.util.HttpSessionMutexListener;

import javax.servlet.http.HttpSessionEvent;
import java.util.Enumeration;

/**
 * session初始化监听类
 * Created by Super Cui on 2017/10/17.
 */
public class SessionInstener extends HttpSessionMutexListener {
    /**
     * 创建session时执行方法
     * @param event
     */
    @Override
    public void sessionCreated(HttpSessionEvent event) {
        System.out.println( "create a new session!");
        super.sessionCreated(event);
    }

    /**
     * session销毁前执行方法
     * @param event
     */
    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        System.err.println( "Session is destroying!" );
        Enumeration<String> attributeNames = event.getSession().getAttributeNames();
        while (attributeNames.hasMoreElements()){
            System.out.println( attributeNames.nextElement() );
        }
        super.sessionDestroyed(event);
    }
}
